﻿using System;
using System.Collections.Generic;
using System.IO;


namespace Utilites
{
    class Logger
    {
        private static bool fileLogEnable = true;
        private static string logFileName = "log.txt";

        public static string LogFileName
        {
            get { return Logger.logFileName; }
            set { Logger.logFileName = value; }
        }

        public static bool FileLogEnable
        {
            get { return Logger.fileLogEnable; }
            set { Logger.fileLogEnable = value; }
        }

        public static void WriteLog(Exception ex)
        {
            WriteLog("\n-------------------------------\n");
            WriteLog("! Error");
            WriteLog("\tError info: {0}", ex.Message);
            WriteLog("\tString: {0}", ex.ToString());
            WriteLog("\n-------------------------------\n");
        }

        public static void WriteLog(string format, params Object[] args)
        {
            string logString = string.Format(format, args);
            WriteLogString(logString);
        }

        public static void WriteLog(Object arg)
        {
            WriteLogString(arg.ToString());
        }

        public static void WriteLog(String arg)
        {
            WriteLogString(arg);
        }

        private static void WriteLogString(string logString)
        {
            Console.WriteLine(logString);

            if (fileLogEnable == true)
            {
                using (StreamWriter writer = new StreamWriter(LogFileName, false))
                {
                    writer.WriteLine(logString);
                    writer.Close();
                }
            }
        }
    }
}
